API: Add snippet field to list=search output
authorRoan Kattouw <catrope@users.mediawiki.org>
Tue, 7 Jul 2009 20:17:54 +0000 (20:17 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Tue, 7 Jul 2009 20:17:54 +0000 (20:17 +0000)
RELEASE-NOTES
includes/api/ApiQuerySearch.php

index 619738d..731ba0b 100644 (file)
@@ -268,6 +268,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 18720) Add anchor field to action=parse&prop=sections output
 * (bug 19423) The initial file description page used caption in user lang
   rather than UI lang
+* Added snippet field to list=search output
 
 === Languages updated in 1.16 ===
 
index 80ae14d..4a3b892 100644 (file)
@@ -48,7 +48,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
        }
 
        private function run($resultPageSet = null) {
-
+               global $wgContLang;
                $params = $this->extractRequestParams();
 
                $limit = $params['limit'];
@@ -87,6 +87,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                        $this->dieUsage("{$what} search is disabled",
                                        "search-{$what}-disabled");
 
+               $terms = $wgContLang->convertForSearchResult($matches->termMatches());
                $titles = array ();
                $count = 0;
                while( $result = $matches->next() ) {
@@ -104,6 +105,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                        if (is_null($resultPageSet)) {
                                $vals = array();
                                ApiQueryBase::addTitleInfo($vals, $title);
+                               $vals['snippet'] = $result->getTextSnippet($terms);
                                $fit = $this->getResult()->addValue(array('query', $this->getModuleName()), null, $vals);
                                if(!$fit)
                                {